<template>
  <div>
    <van-nav-bar
      title="账号注册" />
    <!--使用组件van-form 需要在main.js中引入Form-->
    <van-form @submit="onSubmit">
    <!--使用组件van-field 需要在main.js中引入Field  -->
  <van-field
    v-model="username"
    name="username"
    placeholder="用户名"
    :rules="[
    { required: true, message: '请填写用户名' },
    { pattern: /^\w{3,}/, message:'用户名最少3位哦'}
    ]"
  />
  <van-field
    v-model="password"
    name="password"
    type="password"
    placeholder="密码"
    :rules="[
    { required: true, message: '请填写密码' },
    { pattern: /^\w{3,}/, message:'密码最少3位哦'}
    ]"
  />
  <div style="margin: 16px;">
    <!--使用组件van-button block可以改变button按钮的样式  需要在main.js中引入Button -->
    <van-button  block type="info" native-type="submit">注册</van-button>
  </div>
</van-form>
 <router-link class="link" to="/login">有账号，去登录</router-link>
  </div>
</template>

<script>
// 引入注册接口
import { register } from '@/api/user'
export default {
  name: 'HkzfVantLogin',

  data () {
    return {
      username: '',
      password: ''
    }
  },

  methods: {
    async  onSubmit (values) {
      // console.log(values)
      await register(values)
      // console.log(res)
      this.$toast('注册成功')
      this.$router.push('/login')
    }

  }
}
</script>

<style lang="less" scoped>
.nav-bar {
  background-color:#21b97a;
  color: #fa6d1d;
}
.link {
  color: #069;
  font-size: 12px;
  padding-left: 20px;
  float: left;
}

</style>
